import { ExpandOf } from "../../../../../../Decorator/Decorator";
import { Player } from "../../../../../Model/Server/Demo/Gate/Player";
import { PlayerComponent } from "../../../../../Model/Server/Demo/Gate/PlayerComponent";


/**
 * 使用 Expand 扩展方法
 * 
 * 必须作出以下申明，才能调用对象的扩展方法
 */
declare module "../../../../../Model/Server/Demo/Gate/PlayerComponent" {

    interface PlayerComponent {
        Add(player: Player): void;
        Get(id: number): Player;
        Remove(id: number): void;
    }

}

@ExpandOf(PlayerComponent)
export class PlayerComponentSystem {

    private static Add(self: PlayerComponent, player: Player): void {
        self.idPlayers.Add(player.Id, player);
    }

    private static Get(self: PlayerComponent, id: number): Player {
        const gamer = self.idPlayers.TryGetValue(id);
        return gamer;
    }

    private static Remove(self: PlayerComponent, id: number): void {
        self.idPlayers.Remove(id);
    }

}